/*
 * Copyright 2010 Mark Slater
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
 *
 * 	http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 */

package argo.jdom;

import java.util.LinkedList;
import java.util.List;

/**
 * <p/>
 * Created by IntelliJ IDEA.
 * User: zslajchrt
 * Date: Nov 5, 2010
 * Time: 9:19:46 PM
 */
public class JsonFunctionCallNodeBuilder implements JsonNodeBuilder<JsonNode> {

    private final String functionName;
    private final List<JsonNodeBuilder> paramBuilders = new LinkedList<JsonNodeBuilder>();

    public JsonFunctionCallNodeBuilder(String functionName) {
        this.functionName = functionName;
    }

    public String getFunctionName() {
        return functionName;
    }

    public JsonNode build() {
        List<JsonNode> paramNodes = new LinkedList<JsonNode>();
        for (JsonNodeBuilder paramBuilder : paramBuilders) {
            paramNodes.add(paramBuilder.build());
        }
        return JsonNodeFactories.aJsonFunctionCall(functionName, paramNodes);
    }
    
    public JsonFunctionCallNodeBuilder withParameter(final JsonNodeBuilder paramValue) {
        paramBuilders.add(paramValue);
        return this;
    }
}
